using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Comteck.Dto.Orders;
using Comteck.Dto.Sys;
using Comteck.Ktt.Services.Orders;
using Comteck.Ktt.Services.Sys;
using Microsoft.Extensions.DependencyInjection;

namespace Comteck.Winforms.Data {
  /// <summary>
  /// 
  /// </summary>
  public class ServerDbDataHelper {

    /// <summary>
    /// 自提点标签
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    public static async Task<List<SelfOrgTagDto>> GetAllSelfOrgTagAsync() {
      var result = await SysGlobal.ServiceProvider.GetRequiredService<ISelfOrgTagService>().GetAllAsync();
      return result.ToList();
    }

    /// <summary>
    /// 菜单
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    public static async Task<List<MenuAuthDto>> GetLastMenuListAsync() {
      var result = await SysGlobal.ServiceProvider.GetRequiredService<IMenuAuthService>().GetLastMenuListAsync();
      return result.ToList();
    }

    /// <summary>
    /// 打印数据源
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    public static async Task<AjaxResponse<DataSet>> GetPrintTemplatePrintDataSource(string templateId, List<dynamic> ids) {
      var result = new AjaxResponse<DataSet>() {
        Code = 0
      };

      try {
        result.Data = await SysGlobal.ServiceProvider.GetRequiredService<IPrintTemplateService>().GetPrintTemplatePrintDataSource(new PrintTemplateQuery() {
          Id = templateId,
          PrintList = ids
        });
        result.Code = 1;
      } catch (Exception ex) {
        result.Message = ex.Message;
      }

      return result;
    }
  }
}
